import 'package:easy_refresh/easy_refresh.dart';
import 'package:get/get.dart';
import 'package:largefriends/config/lf_route.dart';
import 'package:largefriends/entity/entities/lf_bool_entity.dart';
import 'package:largefriends/entity/entities/lf_user_entity.dart';
import 'package:largefriends/net/error_handle.dart';
import 'package:largefriends/net/lf_api_url.dart';
import 'package:largefriends/net/lf_dio_util.dart';
import 'package:largefriends/pages/lf_base_controller.dart';
import 'package:largefriends/res/strings/lf_strings.dart';
import 'package:largefriends/utils/lf_dialog_utils.dart';

toBlockedMembers() {
  Get.toNamed(LFRoute.pathBlockedMembers);
}

class LfBlockedMembersLogic extends LfBaseListController<LfUserEntity> {
  @override
  Future<IndicatorResult> getCustomParamHttpRequest(
      {bool isRefresh = false}) async {
    var result = await httpRequest(httpUrl: apiBlockList, refresh: isRefresh);
    return result;
  }

  @override
  getCustomRequestParam({bool isRefresh = false}) {}

  unblock(LfUserEntity userEntity) async {
    showLoading();
    await LfDio().post<LfBoolEntity>(url: apiUnblock, params: {
      'userId': userEntity.userId,
    }).then(
      (value) {
        hideLoading();
        showSnackBar(strUnblockedSuccessfully.tr);
        dataList.remove(userEntity);
        update();
      },
      onError: (error) {
        hideLoading();
        if (error is NetError) {
          showSnackBar(error.msg);
        }
      },
    );
  }

  @override
  bool filterKey({required LfUserEntity value, required LfUserEntity other}) {
    return value.userId == other.userId;
  }
}
